package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzWendaback;
import com.ruoyi.system.service.IDzWendabackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回答Controller
 * 
 * @author ruoyi
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/api/wendaback")
public class DzWendabackApiController extends BaseController
{
    @Autowired
    private IDzWendabackService dzWendabackService;

    /**
     * 查询回答列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzWendaback dzWendaback)
    {
        startPage();
        List<DzWendaback> list = dzWendabackService.selectDzWendabackListWeb(dzWendaback);
        return getDataTable(list);
    }

    /**
     * 导出回答列表
     */
    @Log(title = "回答", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzWendaback dzWendaback)
    {
        List<DzWendaback> list = dzWendabackService.selectDzWendabackListWeb(dzWendaback);
        ExcelUtil<DzWendaback> util = new ExcelUtil<DzWendaback>(DzWendaback.class);
        util.exportExcel(response, list, "回答数据");
    }

    /**
     * 获取回答详细信息
     */
    @GetMapping(value = "/{hfId}")
    public AjaxResult getInfo(@PathVariable("hfId") Long hfId)
    {
        return AjaxResult.success(dzWendabackService.selectDzWendabackByHfId(hfId));
    }

    /**
     * 新增回答
     */
    @Log(title = "回答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzWendaback dzWendaback)
    {
        return toAjax(dzWendabackService.insertDzWendaback(dzWendaback));
    }

    /**
     * 修改回答
     */
    @Log(title = "回答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzWendaback dzWendaback)
    {
        return toAjax(dzWendabackService.updateDzWendaback(dzWendaback));
    }

    /**
     * 删除回答
     */
    @Log(title = "回答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hfIds}")
    public AjaxResult remove(@PathVariable Long[] hfIds)
    {
        return toAjax(dzWendabackService.deleteDzWendabackByHfIds(hfIds));
    }
}
